<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBClientView_default extends KBClientView_common
{	
	

	function &execute(&$manager) {
		
		$categories = &$this->stripVars($manager->getCategoryList(0));
		$entries = &$this->stripVars($manager->getEntryList());

		$data = array();
		$data[] = &$this->getCategoryList($categories, $entries, $manager);
		$data[] = &$this->getEntryList($categories, $entries, $manager);		
		$data = implode('', $data);
		
		return $data;
	}
	 
	
	function &getCategoryList($rows, $entries, $manager) {
		
		if(!$rows)             { return; }
		//$one_category = (count($rows) == 1);
		
		$tpl = &new tplTemplatez($this->template_dir . 'category_list.html');
	
		foreach($rows as $cat_id => $v) {
			
			$v['category_link'] = $this->_getLink('category_', false, $v['id'], true);
			$v['item_img'] = $this->_getItemImg($manager->is_registered, false, true);
			
			//if($one_category) { $v = array(); }
			
			foreach($entries[$cat_id] as $k => $entry) {
				
				$e = array();
				$e['title'] = $entry['title'];
				$e['entry_link'] = $this->_getLink('entry_', false, $entry['id'], true);
				
				$tpl->tplParse($e, 'row/row_entry');
			}

			$tpl->tplSetNested('row/row_entry');
			$tpl->tplParse($v, 'row');
		}
		
		$tpl->tplAssign($this->msg);
		$tpl->tplParse();
		
		return $tpl->tplPrint(1);
	}
	
	
	function &getEntryList($rows, $entries, $manager) {
		
		if(!$entries) { return; }
		
		$tpl = &new tplTemplatez($this->template_dir . 'article_list.html');
	
		foreach($rows as $cat_id => $v) {
				
			$v['category_link'] = $this->_getLink('category_', false, $v['id'], true);
			$v['item_img'] = $this->_getItemImg($manager->is_registered, false, true);
			
			foreach($entries[$cat_id] as $k => $entry) {
				
				$e = array();
				$e['id'] = $entry['id'];
				$e['item_img'] = $this->_getItemImg($manager->is_registered, false, false);
				$e['title'] = $entry['title'];
				//$e['body'] = $this->_parseGlossaryItems($entry['body'], $manager);
				
				$e['body'] = DocumentParser::parseGlossaryItems($entry['body'], $manager);		
				//$e['body'] = DocumentParser::parseLink($row['body'], array($this, '_getLink'));
				
				$e['entry_link'] = $this->_getLink('entry_', false, $entry['id'], true);
				
				$tpl->tplParse($e, 'row/row_entry');
			}

			$tpl->tplSetNested('row/row_entry');
			$tpl->tplParse($v, 'row');
		}
		
		$tpl->tplAssign('base_href', $this->conf['client_home_path']);
		$tpl->tplAssign($this->msg);
		$tpl->tplParse();
		
		return $tpl->tplPrint(1);
	}
}
?>